import request from '../../utils/request'

// 查询部门下拉树结构
export function deptTreeSelect() {
  return request({
    url: '/system/user/deptTree',
    method: 'get',
  })
}

// 查询用户列表
export function listUser(query: any) {
  return request({
    url: '/system/user/list',
    method: 'get',
    params: query,
  })
}

// 查询用户详细
export function getUser(userId?: any) {
  return request({
    url: '/system/user/' + parseStrEmpty(userId),
    method: 'get',
  })
}

// 转换字符串，undefined,null等转化为""
export function parseStrEmpty(str: any) {
  if (!str || str == 'undefined' || str == 'null') {
    return ''
  }
  return str
}

// 新增用户
export function addUser(data: any) {
  return request({
    url: '/system/user',
    method: 'post',
    data: data,
  })
}

// 修改用户
export function updateUser(data: any) {
  return request({
    url: '/system/user',
    method: 'put',
    data: data,
  })
}

// 删除用户
export function delUser(userId: any) {
  return request({
    url: '/system/user/' + userId,
    method: 'delete',
  })
}

// 用户密码重置
export function resetUserPwd(userId:any, password:any) {
  const data = {
    userId,
    password
  }
  return request({
    url: '/system/user/resetPwd',
    method: 'put',
    data: data
  })
}

